﻿Imports Infragistics.Win
Imports Infragistics.Win.UltraWinGrid

Public Class ThousandFormatter
    Implements IEditorDataFilter

#Region "Constructor"
    Public Sub New()
    End Sub
#End Region
    
#Region "Procedures"
    Public Function Convert(ByVal conversionArgs As EditorDataFilterConvertArgs) As Object Implements Infragistics.Win.IEditorDataFilter.Convert
        If conversionArgs.Direction = ConversionDirection.EditorToDisplay Then
            If conversionArgs.Value Is DBNull.Value Then Return 0
            'If conversionArgs.Value.Equals("a") Then Return 0
            Dim cell As UltraGridCell = TryCast(conversionArgs.Context, UltraGridCell)
            Dim lintNumber As Integer
            'AndAlso cell.Column.Key = "BNP ADR"
            If cell IsNot Nothing Then
                conversionArgs.Handled = True
                If Integer.TryParse(conversionArgs.Value, lintNumber) Then
                    'conversionArgs.Value.g
                    Dim dValue As Decimal = System.Convert.ToDecimal(conversionArgs.Value)
                    Return dValue.ToString("#,##0")
                End If
            End If
        End If
        Return conversionArgs.Value
    End Function
#End Region

End Class

Public Class NumericComparer
    Implements IComparer

#Region "Constructor"
    Public Function Compare(ByVal x As Object, ByVal y As Object) As Integer Implements System.Collections.IComparer.Compare
        Dim lintx As Int64
        Dim linty As Int64
        Int64.TryParse(x.Value.ToString.Replace(",", ""), lintx)
        Int64.TryParse(y.Value.ToString.Replace(",", ""), linty)
        Return lintx.CompareTo(linty)
    End Function
#End Region
End Class